package com.ljc;

/**
 * @author clj
 * @date 2023/6/1
 * @desc
 * Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.
 *
 * For example:
 *
 * A -> 1
 * B -> 2
 * C -> 3
 * ...
 * Z -> 26
 * AA -> 27
 * AB -> 28
 * ...
 * Example 1:
 * Input: columnTitle = "A"
 * Output: 1
 *
 * Example 2:
 * Input: columnTitle = "AB"
 * Output: 28
 */
public class E171ExcelSheetColumnNumber {

    public static int titleToNumber(String columnTitle) {
        int number = 0;
        int multiple = 1;
        for (int i = columnTitle.length() - 1; i >= 0; i--) {
            System.out.println("i = " + i);

            int k = columnTitle.charAt(i) - 'A' + 1;
            System.out.println("columnTitle.charAt(i) = " + columnTitle.charAt(i));
            System.out.println("k = " + k);
            number += k * multiple;
            System.out.println("number = " + number);
            multiple *= 26;
            System.out.println("multiple = " + multiple);
            System.out.println("=====================================");
        }
        return number;
    }


    public static void main(String[] args) {
        String columnTitle = "AB";
        System.out.println(titleToNumber(columnTitle));
    }



}
